### GENERATING TABLE C.3: MIGRANT LEARNING 

### USES PNAS DATASET

### REQUIRED PACKAGES
require(multiwayvcov)
require(lmtest)
require(stargazer)

##validation test 3: learning
#part a: individuals learn from their past experiences to inform their perceived ability

learn.hist <- lm(ability.abroad.pre.rev ~ male + age + education + income.imp + mighist.dum + denyhist.dum +factor(parish) , data=pnas)
summary(learn.hist)
learn.hist.clust <- cluster.vcov(learn.hist, pnas$ed.parish)
learn.hist.mcse <- coeftest(learn.hist, learn.hist.clust)
learn.hist.mcse

#partb: individuals learn from the experiences of their networks to inform their perceived ability

learn.net <- lm(ability.abroad.pre.rev ~ male + age + education + income.imp +  net.count +factor(parish) , data=pnas)
summary(learn.net)
learn.net.clust <- cluster.vcov(learn.net, pnas$ed.parish)
learn.net.mcse <- coeftest(learn.net, learn.net.clust)
learn.net.mcse


#for coefficients
stargazer(learn.hist.mcse, learn.net.mcse, align=TRUE, column.labels=c("Personal", "Networks"), 
          omit.stat=c("LL","ser","f"), covariate.labels=c("Male", "Age", "Income", "Education", "Past Migration", "Past Visa Denial", "Network Migration"),title="Ability and Aspiration to Migrate",single.row=FALSE)

#for n
stargazer(learn.hist, learn.net, align=TRUE, column.labels=c("Personal", "Networks"), 
          omit.stat=c("LL","ser","f"), covariate.labels=c("Male", "Age", "Income", "Education", "Past Migration", "Past Visa Denial", "Network Migration"),title="Ability and Aspiration to Migrate",single.row=FALSE)

